"""
订单相关接口
作者：资深Flask讲师
功能：订单管理（示例）
"""

from flask import Blueprint, jsonify, request

orders_blue = Blueprint('orders_blue', __name__)


@orders_blue.route('/list', methods=['GET'])
def order_list():
    """
    获取订单列表（需要token验证）
    """
    # 从request.user_info中获取用户信息
    user_info = getattr(request, 'user_info', None)
    
    # 模拟订单数据
    orders = [
        {"id": 1, "product": "商品A", "price": 99.99, "status": "已发货"},
        {"id": 2, "product": "商品B", "price": 199.99, "status": "待发货"}
    ]
    
    return jsonify({
        "code": 200,
        "message": "获取订单列表成功",
        "data": {
            "user": user_info.get('username') if user_info else None,
            "orders": orders
        }
    })


